import "package:share_image_server/export_all.dart";

//
// auth: Du Long
// date: 2024-09-15
// description:
//

late final String host;
late final int port;
late final String logPath;
late final String imagePath;
late final String checkToken;
late final bool consoleLog;
late final bool infoM;

final Map<String, String> allowedFileTypes = {
  "image/jpeg": "jpg",
  "image/png": "png",
  "image/gif": "gif",
  "image/svg+xml": "svg",
  "image/bmp": "bmp",
  "image/webp": "webp",
  "image/x-icon": "ico",
  "image/tiff": "tiff",
  "image/heif": "heif",
  "image/jp2": "jp2",
  "image/jpx": "jpx",
  "video/mp4": "mp4"
};

late final Map<String, String> allowedContentType;
String pidFilePath = Platform.isWindows
    ? Platform.environment['TEMP']! + "/kpb.pid"
    : "/run/kpb.pid";
final String _filePath = Platform.isWindows
    ? Platform.environment["HOMEPATH"]! + "/kpb.json"
    : "/etc/kpb/config.json";

var config = readConfigFromFile(_filePath).then((v) {
  print("配置文件位置:" + _filePath);
  host = v.host;
  port = v.port;
  imagePath = v.savePath;
  logPath = v.logPath;
  checkToken = v.checkToken;
  infoM = v.infoM;
  consoleLog = v.consoleLog;
  Map<String, String> temp = {};
  allowedFileTypes.forEach((key, value) {
    temp[value] = key;
  });
  allowedContentType = temp;
  try {
    File(logPath).createSync(recursive: true);
    Directory(imagePath).createSync(recursive: true);
  } catch (e) {
    print("IO操作异常,请检测权限或IO占用情况");
    print(e.toString());
  }
});
